<?php
$queryEmployee = mysql_query("SELECT e.FullName,dl.DepartmentName,e.Position 
				FROM employee e INNER JOIN department_lang dl ON dl.IDDepartment = e.IDDepartment
				WHERE e.IDEmployee = '$didemployee' AND dl.LangID = '$lang'");
		
		while ($row = mysql_fetch_array($queryEmployee))
		{
			$dnameemployee = $row[FullName];
			$dnamedepartment = $row[DepartmentName];
			$dposition = $row[Position];
		}
		
$body.="<div>
			<table cellpadding='5' cellspacing='0' style='text-align:center; border:1px solid #C4C0C9; width:100%; border-bottom:none; border-right:none'>
			
		    	
		        <tr>
		        	<td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center; font-weight:bold; background:#eee'>".$l_approver."</td>
		            <td colspan='8' style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:1px; text-align:center;'>
		                <table cellpadding='5' cellspacing='0' style='text-align:center; border:1px solid #C4C0C9; width:100%; border-bottom:none; border-right:none'>";

									
                    				
                    				$i=1;
                    				while ($row = mysql_fetch_array($query1))
                    				{
                    					$dnameapprover = $row[Fullname];
                    					$ddateapproved = $row[DateApprove];
                    					$dcommentm=$row[Description];
                    					$didEmployee=$row[IDEmployee];
                    					if ($row[IDStatus] == 1){
	                    					$dstatus=$l_status_complete;
	                    				} else if ($row[IDStatus] == 2){
	                    					$dstatus=$l_status_pending;
	                    				}else if ($row[IDStatus] == 3){
	                    					$dstatus=$l_status_declined;
	                    				}else if ($row[IDStatus] == 4){
	                    					$dstatus=$l_status_saved;
	                    				}else if ($row[IDStatus] == 5){
	                    					$l_status_reference;
	                    				}
		                
		           $body.=" <tr>
		                        <td width='100px' rowspan='2' style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:blue; height:36px; padding:4px; text-align:center;'>".$l_step." ".$i."</td>
		                        <td width='450px' style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'>
		                        	<span style='display: block;'>
		                    					<b>".$dnameapprover."</b>_".$dstatus." ".$ddateapproved."
		                    		</span>
		                        </td>            
		                        <td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'><div align='center'>".$l_reference." :"; 
		                      	//Get list references
                    				$query2 = mysql_query("SELECT e.Fullname,e.Email,e.IDEmployee FROM list_reference l , employee e 
 														WHERE l.id_group = '$idgroupapprove' AND l.id_manager='$didEmployee' AND l.id_employee=e.IDEmployee;") ;
		                    				$refer=array();
		                    				while ($row1 = mysql_fetch_array($query2))
		                    				{
		                    					$refer[]=array($row1[Fullname],$row1[Email],$row1[IDEmployee]);
		                    					$dnamereferences = $row1[Fullname];
		                       					$body.="<b>".$dnamereferences."</b>;";
		                        
		                    				}
		                    $body.=" </div></td></tr>";
		                    if($ddateapproved !=null){
		                    $body.=" <tr>
		                      	<td colspan='2' style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'><div align='center'><strong>".$l_comment." :</strong> ".$dcommentm."</div></td>
		                    	</tr>";
		                    }else{
		                    	$body.=" <tr>
		                    	</tr>";
		                    }
	                    $i++;
	                    }
		                    
			$body.=" </table> 
		            </td>             
		        </tr>
		        <tr>
		        	<td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center; font-weight:bold; background:#eee'>".$l_create_by."</td>
		        	<td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center; font-weight:bold; background:#eee'>".$l_department."</td>
		            <td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'>".$dnamedepartment."</td>
		            <td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center; font-weight:bold; background:#eee'>".$l_position."</td>
		            <td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'>".$dposition."</td>
		            <td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center; font-weight:bold; background:#eee'>".$l_fullname."</td>
		            <td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'>".$duser."</td>             
		            
		        </tr>
		        <tr>
		        	<td rowspan='2' style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center; font-weight:bold; background:#eee'>".$l_project." (".$l_purpose.")</td>
		            <td colspan='2' rowspan='2' style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'>".$dtitle."</td>            
		            <td rowspan='2' style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center; font-weight:bold; background:#eee'>".$l_bussiness_date." </td>
		            <td style='padding: 3px 5px;border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center; font-weight:bold; background:#eee'>".$l_location." </td>
		            <td colspan='2' style='padding: 3px 5px;border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'>".$dlocation."</td>
		        </tr>
		        <tr>
		        	<td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center; font-weight:bold; background:#eee'>".$l_partner."</td>
		            <td colspan='7' style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'>".$dperforment."</td>            
		        </tr>
		        <tr>
		        	<td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center; font-weight:bold; background:#eee'>".$l_created_date."</td>
		            <td colspan='7' style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'>".$dtime."</td>            
		        </tr>    
		        <tr>
		        	<td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center; font-weight:bold; background:#eee'>".$l_payment_advance."</td>
		            <td colspan='7' style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'>".$l_amount.": ".number_format($dtotalTime)."  ".$l_unit."</td>            
		        </tr>    
		         <tr>
		            <td colspan='8' style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'><b style='font-size: 20px;'>".$l_title_table." </b></td>            
		        </tr>
		        
		        <tr>
		            <td colspan='8' style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'>
		            <table cellpadding='5' cellspacing='0' style='text-align:center; border:2px solid #C4C0C9; width:100%;' >
			       		<tr>
				        	<td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center; font-weight:bold; background:#eee;width:15%'>".$l_items." (*)</td>
				        	<td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center; font-weight:bold; background:#eee;width:55%'>".$l_content."</td>
				        	<td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center; font-weight:bold; background:#eee;width:15%'>".$l_currency."</td>
				        	<td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center; font-weight:bold; background:#eee;width:15%'>".$l_remarks."</td>
			        	</tr>";
			        	$query2 = mysql_query("select adv.items,adv.content,adv.money,adv.notes 
								from ap_advance adv where document_id = '$id_approvedoc'");
						$dtotalmoney = 0;
						while ($row = mysql_fetch_array($query2))
						{
							$dtotalmoney = $dtotalmoney + $row[money];
		            	
		            	$body.="<tr>
		            		<td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'>".$row[items]."</td>
		            		<td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'>".$row[content]."</td>
		            		<td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'>".number_format($row[money])."</td>
		            		<td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'>".$row[notes]."</td>
		            	</tr>";
		            	
		            	}
			
					$body.="
						<tr>
							<td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'>".$l_total."</td>
		            		<td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'></td>
		            		<td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'>".number_format($dtotalmoney)."</td>
		            		<td style='border-bottom:1px solid #c4c0c9; border-right:1px solid #c4c0c9; color:#333; height:36px; padding:4px; text-align:center;'></td>
						</tr>
					</table>
		            </td>            
		        </tr>
		    </table>
		</div>";


?>